<?php
class CacheData extends CacheBase
{
    protected $cacheDir;

    public function CacheData($class_name, $cache_id = null)
    {
        if (!AppConfig::GetInstance()->CACHE_DATA_MODE)
            $this->cachable = false;
        else
        {
            $this->cacheDir = AppConfig::GetInstance()->DIR_CACHE_DATA.DS.$class_name;
            FileHandler::MakeDir($this->cacheDir);
            $hour = SettingModel::Get('CACHE_HOUR_'.$class_name);
            parent::__construct($hour, $this->cacheDir.DS.md5($cache_id).'.tmp');
        }
    }

    public function Render()
    {
        return FileHandler::Load($this->cacheFile);
    }

    public function Save($content)
    {
        if ($this->cachable)
            return FileHandler::Export($this->cacheFile, $content);
    }

    public function SetCacheId($cache_id)
    {
        $this->cacheFile = $this->cacheDir.DS.md5($cache_id);
    }

    public function ClearAll()
    {
        FileHandler::RemoveDir($this->cacheDir);
    }

    public function Clear()
    {
        FileHandler::Remove($this->cacheFile);
    }
}
?>
